package net.yihang.miaosha.dao;

import net.yihang.miaosha.domain.Goods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GoodsDao {

    @Select("select * from miaosha_goods mg inner join goods g on mg.goods_id=g.id")
    public List<Goods> findAll();

    @Select("select * from miaosha_goods mg inner join goods g on mg.goods_id=g.id where goods_id=#{goodId}")
    public Goods findById(long id);

    @Update("update miaosha_goods set stock_count=stock_count-1 where goods_id = #{id} and stock_count>=1")
    int updateStock(long id);
}
